草庐IT

c++ - Clang、std::next、libstdc++ 和 constexpr-ness

全部标签

c++ - 使用 std::aligned_storage 过度对齐的类型

C++标准声明,关于std::aligned_storage模板,Alignshallbeequaltoalignof(T)forsometypeTortodefault-alignment.那是不是说程序中一定有这样的类型,或者说一定是可以做出这样的类型?特别是possibleimplementation建议在cppreference上是templatestructaligned_storage{typedefstruct{alignas(Align)unsignedchardata[Len];}type;};如果可能的话(也就是说,如果Align是有效的对齐方式),这似乎使具有该对

c++ - 如何在 constexpr 函数中强制出现编译错误,而不是让它衰减到非 constexpr 上下文中?

这是我希望能够编写的代码:intid1=not_const_expr_1();intid10=not_const_expr_10();constexprDevice&cD1=get_device(1);//1.okconstexprDevice&cD10=get_device(10);//2.compileerrorDevice&cD1=get_device(1);//3.okDevice&cD10=get_device(10);//4.compileerrorDevice&D1=get_device(id1);//5.okDevice&D10=get_device(id10);//6

c++ - 为什么执行者不在 Concurrency TS 和 std::future 接口(interface)中了?

std::future::then的接口(interface)在论文中N3784包含一个重载版本,该版本接受一个执行程序(在N3562中有更多描述)作为参数。所以如果你想更多地控制回调在哪个线程上执行,你可以这样做。但是这里的官方文档介绍了并发TS中的所有功能http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0159r0.html#futures.unique_future不包括.then()的重载并且根本不提及执行程序。它说Whentheobject'ssharedstateisready,thecontinuation

c++ - 未定义模板的隐式实例化 'std::__1::function<int (double, double, double, double)>'

在我正在进行的项目中,我尝试使用curlpp库来发出一个简单的htmlGET请求。当我将cpp文件传递​​给g++时,出现以下错误:/usr/local/include/curlpp/internal/CurlHandle.hpp:185:42:error:implicitinstantiationofundefinedtemplate'std::__1::function'curlpp::types::ProgressFunctionFunctormProgressFunctor;/usr/local/include/curlpp/internal/CurlHandle.hpp:13

c++ - 通过调用 constexpr 函数定义静态 constexpr 成员

我的问题如下。我想根据constexpr值列表对类型列表进行排序。问题可以归结为这个函数:templateautomin(U,V)->std::conditional_t{return{};}而value必须分别是每种类型的一些静态constexpr成员。以下片段演示了用法://(I)//Thismustevenbedeclaredoutsideofafunctionbodyduetothestatics:(structX{staticconstexprdoublevalue=2.;};structY{staticconstexprdoublevalue=1.;};intmain(){

c++ - 使用 constexpr 或模板元编程简化较长的展开循环表达式

看起来我有一个更长的表达式(展开的循环),例如下面的代码在一个软件中多次膨胀了数千行。由于poly为性能采用模板参数(第二个参数对应于循环z值),我想知道是否可以通过模板元编程简化下面的代码并通过递归构建类似于循环的东西。表达式的语法似乎是每个x=bx(a+b+c*by*bz)+..我想,如果poly不是模板函数,而是采用函数参数,那会更容易一些。voidcalc(floatmat[3][3][3],floatfS,floatfT,floatfU){constfloatbs20_u=poly(fU);constfloatbs21_u=poly(fU);constfloatbs22_u=

c++ - 由于类型不完整,在 static_assert 中使用 std::is_base_of 失败

我想做的是让一些类继承自extention类。问题是extention类必须知道它正在扩展哪个类。这可以像这样简单地实现:templateclassExtention{public:voidcheck()const{std::cout::value{};classBar:publicExtention{};Foo和Bar类显示了扩展的好坏用法。Foo().check();→Extentionisvalid:trueBar().check();→Extentionisvalid:false我想在编译时检查模板的有效性,这让我写了templateclassExtention{static_

c++ - std::hash 用于 std::chrono::duration

我正在尝试在std::chrono::duration上设置一组对象的键。这不会编译:#include#includeclassFoofinal{public:Foo(){}inty;};intmain(void){automap=std::unordered_map,Foo>();map[std::chrono::duration(5)].y=0;return0;}/usr/include/c++/4.9/bits/hashtable_policy.h:Ininstantiationof'structstd::__detail::__is_noexcept_hash>,std::ha

c++ - std::experimental::ostream_joiner 和 std::pair

在c++17/g++7中,终于有了怀念已久的ostream_joiner。它可以正确输出到ostream,使用中缀定界符分隔集合元素。#include#include#include#include#include#includeusingstring=std::string;#if1structpair{stringfirst;stringsecond;};#elseusingpair=std::pair;#endifstd::ostream&operatorpairs={{"foo","bar"},{"baz","42"}};std::copy(std::begin(pairs),

c++ - 从 vector 映射中查找并删除 std::function 对象

我目前正在尝试为我的游戏引擎实现一个消息系统。它使用以下形式的函数回调:typedefstd::functionCallback;它维护一个消息列表:mutablestd::vector>messageList;以及签名的回调字典:mutablestd::map>callbackDictionary;用于调用“绑定(bind)”到特定消息类型的所有回调。调用回调函数时,将传递相应的消息。到目前为止一切顺利。为了更好地理解,这里是订阅方法,它允许用户添加一个函数方法,该方法会为订阅类型的每条消息调用。voidMessenger::Subscribe(Message::Typetype,C